package org.starsource.forum.client.util;

public class ImageRatioHelper {
	private int imageWidth, imageHeight;
	private int containerWidth, containerHeight;
	private int scaleWidth, scaleHeight;
	
	public int getImageWidth() {
		return this.imageWidth;
	}
	public void setImageWidth(int imageWidth) {
		this.imageWidth = imageWidth;
	}
	
	public int getImageHeight() {
		return this.imageHeight;
	}
	public void setImageHeight(int imageHeight) {
		this.imageHeight = imageHeight;
	}
	public void setImageSize(int imageWidth, int imageHeight) {
		setImageWidth(imageWidth);
		setImageHeight(imageHeight);
	}
	
	public int getContainerWidth() {
		return this.containerWidth;
	}
	public void setContainerWidth(int containerWidth) {
		this.containerWidth = containerWidth;
	}
	
	public int getContainerHeight() {
		return this.containerHeight;
	}
	public void setContainerHeight(int containerHeight) {
		this.containerHeight = containerHeight;
	}
	public void setContainerSize(int containerWidth, int containerHeight) {
		setContainerWidth(containerWidth);
		setContainerHeight(containerHeight);
	}
	public int getScaleWidth() {
		return this.scaleWidth;
	}
	
	public int getScaleHeight() {
		return this.scaleHeight;
	}
	
	public ImageRatioHelper() {
		
	}
	public ImageRatioHelper(int imageWidth, int imageHeight, int containerWidth, int containerHeight) {
		setImageSize(imageWidth, imageHeight);
		setContainerSize(containerWidth, containerHeight);
	}
	
	public void calculateScale() {
		if (this.containerWidth >= this.imageWidth && this.containerHeight >= this.imageHeight) {
			this.scaleWidth = this.imageWidth;
			this.scaleHeight = this.imageHeight;
//			logger.debug("Image can be hold in container without scale");
			return;
		}
		
		if (containerWidth * imageHeight >= containerHeight * imageWidth) {
			this.scaleHeight = this.containerHeight;
			this.scaleWidth = this.imageWidth * this.scaleHeight / this.imageHeight;
//			logger.debug("set Scale height to container height");
			return;
		}
		
		this.scaleWidth = this.containerWidth;
		this.scaleHeight = this.imageHeight * this.scaleWidth / this.imageWidth;
//		logger.debug("set Scale width to container width");
	}
	
}
